package per.yd.tankWar.entity.tool;

import java.awt.Graphics;
import java.awt.Image;
import java.util.Random;

import per.yd.tankWar.constants.ToolEnum;
import per.yd.tankWar.entity.DisplayImage;

public class Tool extends DisplayImage{
	private int timer = 0;
	
	private int aliveTime = 4500;
	
	private static int height = 20, width = 20;
	
	private static Image[] images = ToolsImage.getToolsImage();
	
	private Random random = new Random();
	
	public ToolEnum toolEnum;
	
	private boolean alive = true;
	
	public static Tool getToolInstance(int x, int y) {
		return new Tool(x, y);
	}
	
	
	private Tool(int x, int y) {
		super(x,y,height,width);
		toolEnum = ToolEnum.values()[random.nextInt(6)];
	}
	
	public void changeToolEnum() {
		toolEnum = ToolEnum.values()[random.nextInt(6)];
		x = random.nextInt(500);
		y = random.nextInt(550);
		this.alive = true;
		
	}
	
	public void drawTool(Graphics g) {
		if(timer > aliveTime) {
			timer = 0;
			alive = false;
		} else {
			g.drawImage(images[toolEnum.ordinal()], x, y, null);
		}
	}
	
	
	public void setAlive(boolean alive) {
		this.alive = alive;
	}
	
	
	public boolean isAlive() {
		return alive;
	}
	
}
